<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Grid extends Model
{
    use SoftDeletes;

    protected $table = 'grid';

    protected $fillable = [
        'name',
        'street_id',
        'village_id',
        'project_id',
        'segment_id',
        'grid_group_id',
        'opinion',
        'assess_company_id',
        'mapping_company_id',
        'house_use',
        'build_form',
        'supply_form',
        'dualuse_area',
        'disagree_reason',
        'if_agent',
        'receive_villager_id',
        'address',
        'business_imgs',
        'business_num',
        'business_award_time',
        'idcard_status',
        'hukou_status',
        'fangchan_status',
        'area_status',
        'into_door_status',
        'mapping_status',
        'assess_status',
        'house_status',
        'vacate_room_status',
        'sign_status',
        'settlement_status',
        'bank_status',
        'grant_status',
        'if_sign',
        'for_user_id',
        'if_mapping',
        'if_build',
        'sign_time',
        'sign_num',
        'pid',
    ];

    public function villager()
    {
        return $this->hasMany(Villager::class, 'grid_id', 'id');
    }

    public function agent()
    {
        return $this->hasOne(Agent::class, 'grid_id', 'id');
    }

    public function grid_area()
    {
        return $this->hasOne(GridArea::class, 'grid_id', 'id');
    }

    public function grid_area_arr()
    {
        return $this->hasMany(GridArea::class, 'grid_id', 'id');
    }

    public function grid_house()
    {
        return $this->hasMany(GridHouse::class, 'grid_id', 'id');
    }

    public function grid_house_2()
    {
        return $this->hasMany(GridHouse::class, 'grid_id', 'id');
    }

    public function grid_img()
    {
        return $this->hasMany(GridImg::class, 'grid_id', 'id');
    }

    public function grid_img_2()
    {
        return $this->hasOne(GridImg::class, 'grid_id', 'id');
    }

    public function grid_price()
    {
        return $this->hasOne(GridPrice::class, 'grid_id', 'id');
    }

    public function grid_price_arr()
    {
        return $this->hasMany(GridPrice::class, 'grid_id', 'id');
    }

    public function street()
    {
        return $this->hasOne(Street::class, 'id', 'street_id');
    }
    public function village()
    {
        return $this->hasOne(Village::class, 'id', 'village_id');
    }
    public function grid_group()
    {
        return $this->hasOne(GridGroup::class, 'id', 'grid_group_id');
    }
    public function segment()
    {
        return $this->hasOne(Segment::class, 'id', 'segment_id');
    }
    public function approval_list()
    {
        return $this->hasOne(ApprovalList::class, 'grid_id', 'id')->latest();;
    }
}
